<div class="layui-row layui-col-space15">
	<div class="layui-col-xs6 layui-col-md3">
		<div class="layui-card">
			<div class="layui-card-header">
				设备数量
			</div>
			<div class="layui-card-body">
				<p class="lay-big-font" id="sbsl">--</p>
			</div>
		</div>
	</div>
	<div class="layui-col-xs6 layui-col-md3">
		<div class="layui-card">
			<div class="layui-card-header">
				上线设备
			</div>
			<div class="layui-card-body">
				<p class="lay-big-font" id="sxsb">--</p>
			</div>
		</div>
	</div>
	<div class="layui-col-xs6 layui-col-md3">
		<div class="layui-card">
			<div class="layui-card-header">
				用户总数
			</div>
			<div class="layui-card-body">
				<p class="lay-big-font" id="yhzs">--</p>
			</div>
		</div>
	</div>
	<div class="layui-col-xs6 layui-col-md3">
		<div class="layui-card">
			<div class="layui-card-header">
				今日活跃
			</div>
			<div class="layui-card-body">
				<p class="lay-big-font" id="hyyh">--</p>
			</div>
		</div>
	</div>
	<div class="layui-clear"></div>
</div>

<div class="layui-card ">
	<div class="layui-tab">
		<ul class="layui-tab-title ">
			<li class="layui-this">更新日志</li>
			<li>消息列表</li>
		</ul>
		<div class="layui-tab-content zbycontent">
			<div class="layui-tab-item layui-show">
				<div class="layui-card">
					<div class="layui-card-body">
						<ul class="layui-timeline zby_cy">
							<!--<li class="layui-timeline-item">
								<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
								<div class="layui-timeline-content layui-text">
									<h3 class="layui-timeline-title">V1.16
                                <small>松果健康app上线</small>&emsp;<span class="layui-badge-rim">2018-09-03</span>
                            </h3>
									<ul>
										<li>增加在线健康咨询功能</li>
										<li>完善信息选项优化</li>
										<li>已知bug修复</li>
									</ul>
								</div>
							</li>
							<li class="layui-timeline-item">
								<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
								<div class="layui-timeline-content layui-text">
									<h3 class="layui-timeline-title">V1.15
                                <small></small>&emsp;<span class="layui-badge-rim">2018-08-15</span>
                            </h3>
									<ul>
										<li>针对睡眠，心率，步数数据同步进一步优化</li>
										<li>留言板性能优化</li>
										<li>健康提醒推送</li>
									</ul>
								</div>
							</li>
							<li class="layui-timeline-item">
								<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
								<div class="layui-timeline-content layui-text">
									<h3 class="layui-timeline-title">V1.14&emsp;<span class="layui-badge-rim">2018-07-31</span>
                            </h3>
									<ul>
										<li>一键测试倒计时为1分钟时，断开bug修复</li>
										<li>增加留言和意见反馈功能</li>
										<li>睡眠，心率，步数数据同步bug修复</li>
										<li>部分用户一键测试结束后，上传成功无结果修复</li>
										<li>脏腑平衡状态，静息心率调整为当次一键测量心率</li>
									</ul>
								</div>
							</li>
							<li class="layui-timeline-item">
								<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
								<div class="layui-timeline-content layui-text">
									<h3 class="layui-timeline-title">V1.13&emsp;<span class="layui-badge-rim">2018-07-15</span>
                            </h3>
									<ul>
										<li>一键测试结束后，提示“参数错误”bug修复</li>
										<li>手机，微信，QQ账号登录打通</li>
										<li>睡眠，心率，步数数据同步bug修复</li>
										<li>一键测试界面优化</li>
									</ul>
								</div>
							</li>
							<li class="layui-timeline-item">
								<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
								<div class="layui-timeline-content layui-text">
									<h3 class="layui-timeline-title">V1.12&emsp;<span class="layui-badge-rim">2018-06-30</span>
                            </h3>
									<ul>
										<li>晋级模块升级，增加冥想、饮食、运动建议功能</li>
										<li>完善一键测量，增加血压分析功能</li>
										<li>修复了部分bug，提升用户体验</li>
									</ul>
								</div>
							</li>
							<li class="layui-timeline-item">
								<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
								<div class="layui-timeline-content layui-text">
									<h3 class="layui-timeline-title">V1.0
                                <small>松果健康app上线</small>&emsp;<span class="layui-badge-rim">2018-06-01</span>
                            </h3>
								</div>
							</li>
						-->
						</ul>
					</div>
				</div>
			</div>
			<div class="layui-tab-item">
				<div id="msgl">
					<table class="layui-hide" id="msglist" lay-filter="msgList"></table>
				</div>
				<div id="msgXq"><br />
					<div class="layui-card">
						<div class="layui-card-header zbyt">
							<h1 id="mtit"></h1>
							<p id="msj"></p>
						</div>
						<div class="layui-card-body">
							<p id="mnr"></p>
							<button id="fh" class="layui-btn layui-btn-primary  layui-btn-xs zbyfhsc">返回上一层</button>
						</div>
					</div>
				</div>

			</div>
		</div>
	</div>

</div>
<script type="text/html" id="usernameTpl">
	<a href="/?table-demo-id={{d.id}}" class="layui-table-link" target="_blank">{{ d.username }}</a>
</script>

<script>
	function showMssage(datas) {
		layui.use(['table', 'config'], function() {
			var table = layui.table;
			var config = layui.config;
			var alog = config.getTempData('loginInfo');
			var a;

			if(alog.orgId == 1) {
				a = ""
			} else {
				a = "" + alog.orgId
			}

			table.render({
				elem: '#msglist',
				id: 'msglist',
				data: datas,
				cols: [
					[{
						type: 'checkbox'
					}, {
						field: 'source',
						title: '来自',
						event: "lz"
					}, {
						field: 'title',
						title: '消息标题',
						event: "bt"
					}, {
						field: 'addTime',
						title: '日期',
						event: "rq",
						templet: function(b) {
							if(b.addTime != null) {
								return b.addTime.substring(0, 10)
							} else {
								return ''
							}
						}
					}]
				],
				//			page: true
			});
			table.on('tool(msgList)', function(obj) {
				var data = obj.data;
				if(obj.event == 'lz' || obj.event == 'bt' || obj.event == 'rq') {
					$('#msgl').css("display", "none")
					$('#msgXq').css("display", "block")
					$('#mtit').html(data.title);
					$('#msj').html(data.addTime)
					$('#mnr').html(data.content)
				}

			})
			userSexZs(a)
			showMainCount(a)
		});
	}
	showMsg()
	bb()

	$('#fh').click(function() {
		$('#msgXq').css("display", "none")
		$('#msgl').css("display", "block")
		$('#mtit').html('');
		$('#msj').html('')
		$('#mnr').html('')
	})

	function showMainCount(x) {

		$.ajax({
			type: "POST",
			url: mainCountTotal,
			data: {
				params: JSON.stringify({
					orgId: x
				})
			},
			dataType: "json",
			xhrFields: {
				withCredentials: true
			},
			beforeSend: function(request) {},
			success: function(data) {
				$('#sbsl').html(data.totalDevice);
				$('#sxsb').html(data.onlineDevice);
				$('#hyyh').html(data.activeUser);
			},
			beforeSend: function() {},
			complete: function() {},
			error: function(result) {
				console.log(result);
			},
		});
	}

	function showMsg() {
		$.ajax({
			type: "POST",
			url: getNotices,
			data: {},
			dataType: "json",
			xhrFields: {
				withCredentials: true
			},
			beforeSend: function(request) {},
			success: function(data) {
				showMssage(data)
			},
			beforeSend: function() {},
			complete: function() {},
			error: function(result) {
				console.log(result);
			},
		});
	}

	function userSexZs(x) {
		// 性别
		$.ajax({
			type: "POST",
			url: countSex,
			data: {
				params: JSON.stringify({
					sex: "",
					orgId: x,
				})
			},
			dataType: "json",
			xhrFields: {
				withCredentials: true
			},
			success: function(data) {
				$('#yhzs').html(data[0].sums)
			},
			error: function(result) {
				console.log(result);
			},
		});
	}

	function bb() {
		// 性别
		$.ajax({
			type: "POST",
			url: banb,
			data: {
				params: JSON.stringify({
					pageSize: 1000,
					pageNumber: 1,
				})
			},
			dataType: "json",
			xhrFields: {
				withCredentials: true
			},
			success: function(data) {
				var a = ""
				for(var i = 0; i < data.length; i++) {
					a += '<li class="layui-timeline-item">' +
						'<i class="layui-icon layui-timeline-axis">&#xe63f;</i>' +
						'<div class="layui-timeline-content layui-text">' +
						'<h3 class="layui-timeline-title">' + data[i].versionCode.split(' ')[0]
					if( data[i].versionCode.split(' ')[1]) {
						a += ' <small>' + data[i].versionCode.split(' ')[1] + '</small>&emsp;<span class="layui-badge-rim">' + data[i].addTime.split(' ')[0] + '</span>' + '</h3>'
					} else {
						a += ' <small></small>&emsp;<span class="layui-badge-rim">' + data[i].addTime.split(' ')[0] + '</span>' + '</h3>'
					}
					var b = data[i].content.split('*')
					if(b[0] != "") {
						a += '<ul>'
						for(var j = 0; j < b.length; j++) {
							a += '<li>' + b[j] + '</li>'
						}
						a += '</ul>'
					}
					a += '</div></li>'
				}

				$(".zby_cy").html(a);

			},
			error: function(result) {
				console.log(result);
			},
		});
	}
</script>